// pages/test/index.js
import {
  config
} from "../../config"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    awardList:[
      '第1个格子谢谢参与',
			'第2个格子抱枕',
			'第3个格子签名海报',
			'第4个格子签名篮球',
			'第5个格子红牛一罐1',
			'第6个格子红牛一罐2',
    ],
    drawType:'',
    isShowRecord:true,
    recordData:null,
  },
  getResult(e){
    const result = e.detail
    this.setData({
      recordData:result.curKey
    })
    if(result.ifWinning){
      if(result.curKey==5||result.curKey==6){
        wx.navigateTo({
          url: '../drawResult/index?result=2',
        })
      }
      if(result.curKey==2){
        wx.navigateTo({
          url: '../drawResult/index?result=1',
        })
      }
      if(result.curKey==3){
        wx.navigateTo({
          url: '../drawResult/index?result=3',
        })
      }
      if(result.curKey==4){
        wx.navigateTo({
          url: '../drawResult/index?result=4',
        })
      }
      if(result.curKey==1){
        wx.navigateTo({
          url: '../drawResult/index?result=0',
        })
      }
    }else{
      wx.navigateTo({
        url: '../drawResult/index?result=0',
      })
    }
  },
  record(){//中奖记录跳转
    const result = {
      curKey:this.data.recordData
    }
    if(result.curKey==5||result.curKey==6){
      wx.navigateTo({
        url: '../drawResult/index?result=2',
      })
    }
    if(result.curKey==2){
      wx.navigateTo({
        url: '../drawResult/index?result=1',
      })
    }
    if(result.curKey==3){
      wx.navigateTo({
        url: '../drawResult/index?result=3',
      })
    }
    if(result.curKey==4){
      wx.navigateTo({
        url: '../drawResult/index?result=4',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      drawType:options.drawType
    })
    //this.getRecord()
  },
  getRecord(){
    const openId = wx.getStorageSync('openid')
    wx.request({
      url: `${config.api_blink_url}/redbull/user?openid=${openId}`,
      method: "post",
      header: {
        'content-type': 'application/json'
      },
      success: (res) => {
       if(res.data.g_draw!==null){
         this.setData({
           isShowRecord:true
         })
         this.setData({
          recordData:res.data.g_draw
         })
       }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   // this.getRecord()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})